package com.sikaryofficial.workbench.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.sikaryofficial.common.core.domain.R;
import com.sikaryofficial.common.core.utils.PageUtil;
import com.sikaryofficial.common.core.web.controller.BaseController;
import com.sikaryofficial.common.core.web.domain.PageResult;
import com.sikaryofficial.workbench.domain.dto.req.goods.GoodsFilterReq;
import com.sikaryofficial.workbench.domain.dto.req.goods.GoodsListReq;
import com.sikaryofficial.workbench.domain.dto.resp.goods.GoodsDTO;
import com.sikaryofficial.workbench.domain.dto.resp.goods.GoodsFilterDTO;
import com.sikaryofficial.workbench.domain.vo.goods.GoodsCategory;
import com.sikaryofficial.workbench.manager.GoodsManager;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * 商品rest接口定义
 *
 * @author qinjinyuan
 * @date 2024-09-23
 */
@RestController
@RequestMapping("/goods")
@Api(tags = "渠道商-商品模块")
@Slf4j
public class GoodsController extends BaseController {
    @Autowired
    private GoodsManager goodsManager;

    /**
     * 商品树结构查询
     */
    @GetMapping("/removeCache")
    @ApiOperation("商品缓存清理")
    public R<Void> removeCache() {
        goodsManager.removeCache();
        return R.ok();
    }

    /**
     * 商品树结构查询
     */
    @PostMapping("/scopeTree")
    @ApiOperation("商品树结构查询")
    public R<Map<String, List<GoodsDTO>>> scopeTree() {
        return R.ok(goodsManager.scopeTree());
    }

    /**
     * 商品查询筛选条件 filter
     */
    @PostMapping("/navigation")
    @ApiOperation("商品-导航数据查询")
    public R<List<GoodsCategory>> navigation() {
        return R.ok(goodsManager.navigation());
    }

    /**
     * 商品查询筛选条件 filter
     */
    @PostMapping("/filter")
    @ApiOperation("商品查询筛选条件-filter")
    public R<GoodsFilterDTO> goodsFilter(@RequestBody GoodsFilterReq req) {
        return R.ok(goodsManager.goodsFilter(req));
    }

    /**
     * 商品推荐列表
     */
    @PostMapping("/recommendList")
    @ApiOperation("商品推荐列表")
    public PageResult<GoodsDTO> goodsRecommendPage(@Validated @RequestBody GoodsListReq req) {
        IPage<GoodsDTO> page = goodsManager.goodsRecommendPage(req);
        return PageUtil.success(page.getRecords(), page.getTotal());
    }

    /**
     * 商品分页列表
     */
    @PostMapping("/listPage")
    @ApiOperation("商品分页列表")
    public PageResult<GoodsDTO> goodsListPage(@Validated @RequestBody GoodsListReq req) {
        IPage<GoodsDTO> page = goodsManager.goodsListPage(req);
        return PageUtil.success(page.getRecords(), page.getTotal());
    }

    /**
     * 商品分页列表
     */
    @GetMapping("/detail/{goodsId}")
    @ApiOperation("商品详情")
    public R<GoodsDTO> detail(@PathVariable(name = "goodsId") Long goodsId) {
        return R.ok(goodsManager.detail(goodsId));
    }

}
